/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
//package oop.demo.bankingtasklistgui;
package BankingTaskListGUI;

/**
 * use ArrayList to set the priority
 * @author ashongtical
 * @author Anka
 */
// import necessary packages
import java.util.ArrayList;

public class TaskManager {
    //use ArrayList to manage the data
    private ArrayList<String> highPriority = new ArrayList<>();
    private ArrayList<String> lowPriority = new ArrayList<>();

    public TaskManager() {
       //create new ArrayList object for priorities
       // No need to initialize as they are already initialized in the declaration
    }

    // Adds a task to the appropriate list based on priority.
    // Tasks containing a * are considered high-priority.
    public void addTask(String task) {
        if (task.contains("*")) {
            highPriority.add(task);
            System.out.println("High-priority task added: " + task);
        } else {
            lowPriority.add(task);
            System.out.println("Low-priority task added: " + task);
        }
    }

    // Removes a task by index from the specified priority list.
    public void removeTask(String priority, int index) {
        if (priority.equals("high")) {
            if (index >= 0 && index < highPriority.size()) {
                System.out.println("Removing high-priority task: " + highPriority.get(index));
                highPriority.remove(index);
            } else {
                System.out.println("Invalid index for high-priority tasks.");
            }
        } else if (priority.equals("low")) {
            if (index >= 0 && index < lowPriority.size()) {
                System.out.println("Removing low-priority task: " + lowPriority.get(index));
                lowPriority.remove(index);
            } else {
                System.out.println("Invalid index for low-priority tasks.");
            }
        } else {
            System.out.println("Invalid priority type. Use 'high' or 'low'.");
        }
    }

    // Change task priority
    // allows moving tasks between high and low priority lists
    public void changePriority(String priority, int index) {
        if (priority.equals("high")) {
            if (index >= 0 && index < highPriority.size()) {
                String task = highPriority.remove(index);
                System.out.println("Changing priority of task: " + task);
                lowPriority.add(task);
            } else {
                System.out.println("Invalid index for high-priority tasks.");
            }
        } else if (priority.equals("low")) {
            if (index >= 0 && index < lowPriority.size()) {
                String task = lowPriority.remove(index);
                System.out.println("Changing priority of task: " + task);
                highPriority.add(task);
            } else {
                System.out.println("Invalid index for low-priority tasks.");
            }
        } else {
            System.out.println("Invalid priority type. Use 'high' or 'low'.");
        }
    }

    // Promote a high-priority task 
    // moves a high-priority task up in the list
    public void promoteTask(int index) {
        if (index >= 0 && index < highPriority.size()) {
            String task = highPriority.remove(index);
            System.out.println("Promoting high-priority task: " + task);
            highPriority.addFirst(task); // Move to the top of the list
        } else {
            System.out.println("Invalid index for high-priority tasks.");
        }
    }
    
    // list getters
    // Get high-priority tasks
    // return copies of the lists to avoid direct modification
    public ArrayList<String> getHighPriorityTasks() {
        return new ArrayList<>(highPriority);
    }

    // Get low-priority tasks
    // return copies of the lists to avoid direct modification
    public ArrayList<String> getLowPriorityTasks() {
        return new ArrayList<>(lowPriority);
    }

    // Display tasks
    public void displayTasks() {
        System.out.println("\nHigh Priority Tasks:");
        for (int i = 0; i < highPriority.size(); i++) {
            System.out.println(i + ". " + highPriority.get(i));
        }

        System.out.println("\nLow Priority Tasks:");
        for (int i = 0; i < lowPriority.size(); i++) {
            System.out.println(i + ". " + lowPriority.get(i));
        }
    }
}
